<template>
    <el-dialog v-if="dialogVisible" :close-on-click-modal='false' :append-to-body="true" title="添加标签" :visible.sync="dialogVisible" @close="resetForm('addForm')" width="400px">
        <el-form label-position="top" :model="addForm" :hide-required-asterisk='true' ref="addForm" class="dialog_form">
            <el-form-item label="" prop="tags" :rules="[{required: true,message: '请输入标签名称',trigger: ['blur', 'change']}]" style="margin-bottom:0">
                <div slot="label" class="tab_label">
                    <div>标签名称</div>
                    <div class="tag_tips">请确认标签名称是否正确，添加后不可修改与删除！</div>
                </div>
                <el-input v-model="addForm.tags" placeholder="请输入标签名称"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button size="small" @click="resetForm('addForm')" class="el-button-width">取 消</el-button>
            <el-button size="small" type="primary" @click="submitForm('addForm')" :disabled="loading" :loading="loading" class="el-button-width">保 存</el-button>
        </span>
    </el-dialog>
</template>

<script>
export default {
    name: "",
    data() {
        
        return {
            loading: false,
            dialogVisible: false,
            addForm: {
                tags: "",
            },
        };
    },
    created() {
       
    },
    methods: {
        getData(){
            this.dialogVisible = true
        },
        // 提交添加
        submitForm(formName) {
            this.$refs[formName].validate(async (valid) => {
                if (valid) {
                    this.loading = true;
                    const { data: res } = await this.$http.post(
                        "fxdata/sellibrary/tagAdd",
                        this.addForm
                    );
                    if (res.code !== 200) {
                        this.$message.error(res.msg);
                        this.loading = false;
                        return;
                    } else {
                        this.$message({
                            message: "添加成功",
                            type: "success",
                        });
                        this.loading = false;
                        this.resetForm(formName);
                        this.$emit("getTagList")
                    }
                } else {
                    this.loading = false;
                    return false;
                }
            });
        },

        // 关闭重置表单
        resetForm(formName) {
            this.$refs[formName].resetFields();
            this.dialogVisible = false;
        },
    },
    components: {},
};
</script>


<style scoped>
.tab_label{
    line-height: 17px;
}
.tag_tips{
    color: #B4B7BD;
    margin-top: 4px;
    margin-bottom: 10px;
}
</style>
